package com.xingkeduo.util.pojo.exception;

/**
 * 授权错误的异常，用于安全拦截器、签名和令牌的生成与验证
 * 
 * @author GJ
 * @time 2018年12月12日 下午4:09:32
 * @description
 */
public class AuthorityException extends RuntimeException
{
	private static final long serialVersionUID = -8132022656936946215L;

	public enum Type
	{
		DEFAULT("01001", ""), OUTTER("01002", "禁止外部访问"), KEY("01002", "密钥错误"), LOGIN("01003", "未登陆"), SIGN("01004", "签名错误"), TOKEN("01005",
				"令牌错误"), PERMISSION("01006", "权限错误");

		private String code;
		private String msg;

		private Type(String code, String msg)
		{
			this.code = code;
			this.msg = msg;
		}

		public String getCode()
		{
			return this.code;
		}

		public String getMsg()
		{
			return this.msg;
		}
	}

	public AuthorityException(Type type, String message)
	{
		StringBuffer messageCreator = new StringBuffer().append(message).append(type.msg);
		this.message = messageCreator.toString();
		this.code = type.code;
	}

	public AuthorityException(Type type)
	{
		StringBuffer messageCreator = new StringBuffer().append(type.msg);
		this.message = messageCreator.toString();
		this.code = type.code;
	}

	private String code;
	private String message;

	public String getCode()
	{
		return code;
	}

	public static String getDefaultCode()
	{
		return Type.DEFAULT.code;
	}

	public void setCode(String code)
	{
		this.code = code;
	}

	public String getMessage()
	{
		return message;
	}

	public void setMessage(String message)
	{
		this.message = message;
	}
}
